<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flags Manager</title>
    <!-- <link href="../css/bootstrap.css" rel="stylesheet" type="text/css"> -->
    <link href="../css/bootstrap-3.3.4.css" rel="stylesheet" type="text/css">
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="container">
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4 center-block">
            <button type="button" class="btn btn-default center-block" onclick="location.href='setup.php?action=setup'">Setup Database</button>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4 center-block">
            <button type="button" class="btn btn-default center-block" onclick="location.href='setup.php?action=insert'">Insert Test Data</button>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4 center-block">
            <button type="button" class="btn btn-default center-block" onclick="location.href='setup.php?action=clear'">Clear flags</button>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4 center-block">
            <button type="button" class="btn btn-default center-block" onclick="location.href='flags.php?action=showall&start=0&number=20'">Go to Index</button>
        </div>
    </div>
</div>
</body>
</html>
<?php
/**
 * Created by PhpStorm.
 * User: Weizehua
 * Date: 8/7/2016
 * Time: 18:34
 */

include_once('../core/database.php');
if(isset($_REQUEST['action']))
{
    $action = $_REQUEST['action'];
    if($action == 'setup')
    {
        if(db_flags_set_up())
        {
            echo "setup succeed!";
        }
        else
            echo "setup failed ...";
    }
    if($action == 'insert')
    {
        $flag = new Flag();
        $flag->server = "Setup Page";
        $flag->flag = "test flag";
        if(flags_insert($flag))
        {
            echo "insert succeed!";
        }
        else
            echo "insert failed...";
    }
    if($action=='clear')
    {
        echo "clear result : " . strval(flags_clear());
    }
}
